package com.huiztech.watersoil.utils;

import com.huiztech.watersoil.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
/**
 * 更多详情适配器
 * @author alin
 *
 */
public class DataAdapter2 extends BaseExpandableListAdapter {     
    private String[] group;   
    private String[][] buddy;  
    private Context context;  
    private ImageButton detailHelpButton;
    private ImageView unitImage;
    LayoutInflater inflater;  
      
    public DataAdapter2(Context context,String[] group,String[][] buddy){  
        this.context=context;  
        inflater = LayoutInflater.from(context);  
        this.group=group;  
        this.buddy=buddy;  
    }  
    public Object getChild(int groupPosition, int childPosition) {  
        return buddy[groupPosition][childPosition];  
    }  
  
    public long getChildId(int groupPosition, int childPosition) {  
        return childPosition;  
    }  
  
    public View getChildView(int groupPosition, int childPosition, boolean arg2, View convertView,  
            ViewGroup arg4) {  
        convertView = inflater.inflate(R.layout.detail_listview_child_item, null);  
        TextView nickTextView=(TextView) convertView.findViewById(R.id.listview_child_nick);
        TextView detail_help_hint=(TextView) convertView.findViewById(R.id.detail_help_hint); 
        detailHelpButton =(ImageButton) convertView.findViewById(R.id.detail_help_button);
        unitImage = (ImageView) convertView.findViewById(R.id.unit_image);

        if(childPosition==0){
        	unitImage.setImageResource(R.drawable.tkm);
        }
        if(childPosition==1){
        	unitImage.setImageResource(R.drawable.tent);
        	detailHelpButton.setVisibility(View.GONE);
        	detail_help_hint.setVisibility(View.GONE);
        }
        nickTextView.setText(getChild(groupPosition, childPosition).toString());  
        if(childPosition==0&&(!nickTextView.getText().toString().equals("请输入降雨值"))){
        	unitImage.setVisibility(1);
        }else if(childPosition==1&&(!nickTextView.getText().toString().equals(""))){
        	unitImage.setVisibility(1);
        }
        else{
        	unitImage.setVisibility(View.GONE);
        }
        return convertView;  
    }  
  
    public int getChildrenCount(int groupPosition) {  
        return buddy[groupPosition].length;  
    }  
  
    public Object getGroup(int groupPosition) {  
        return group[groupPosition];  
    }  
  
    public int getGroupCount() {  
        return group.length;  
    }  
  
    public long getGroupId(int groupPosition) {  
        return groupPosition;  
    }  
  
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup arg3) {  
        convertView = inflater.inflate(R.layout.detail_listview_group_item, null);  
        TextView groupNameTextView=(TextView) convertView.findViewById(R.id.listview_group_name);  
        groupNameTextView.setText(getGroup(groupPosition).toString());  
        ImageView image = (ImageView) convertView.findViewById(R.id.listview_image);  
        ImageView image2 = (ImageView) convertView.findViewById(R.id.arrow_image);  
        image2.setImageResource(R.drawable.down);  
        ImageView help_image = (ImageView) convertView.findViewById(R.id.help_image);
        help_image.setImageResource(R.drawable.help_circle);
    	if(groupPosition == 0){
    		image.setImageResource(R.drawable.one);  
    		help_image.setTag("1");
    	}
    	if(groupPosition == 1){
    		image.setImageResource(R.drawable.two);
    		help_image.setTag("2");
    	}
    	if(groupPosition == 2){
    		image.setImageResource(R.drawable.three);
    		help_image.setTag("3");
    	}
    	if(groupPosition == 3){
    		image.setImageResource(R.drawable.four);
			help_image.setTag("4");
    	}
    	if(groupPosition == 4){
    		image.setImageResource(R.drawable.five);
			help_image.setTag("5");
    	}
    	if(groupPosition == 5){
    		image.setImageResource(R.drawable.six);
    		help_image.setTag("6");
    	}
    	if(groupPosition == 6){
    		image.setImageResource(R.drawable.seven);
			help_image.setTag("7");
    	}
    	if(groupPosition == 7){
    		image.setImageResource(R.drawable.eight);
			help_image.setTag("8");
    	}
    	if(groupPosition == 8){
    		image.setImageResource(R.drawable.nine);
			help_image.setTag("9");
    	}
    	if(groupPosition == 9){
    		image.setImageResource(R.drawable.ten);
			help_image.setTag("10");
    	}
    	if(groupPosition == 10){
    		image.setImageResource(R.drawable.eleven);  
			help_image.setTag("11");
    	}
        //更换展开分组图片  
        if(!isExpanded){  
        	image2.setImageResource(R.drawable.up);  
        	if(groupPosition == 0)
        		image.setImageResource(R.drawable.one);  
        	if(groupPosition == 1)
        		image.setImageResource(R.drawable.two);
        	if(groupPosition == 2)
        		image.setImageResource(R.drawable.three);
        	if(groupPosition == 3)
        		image.setImageResource(R.drawable.four);
        	if(groupPosition == 4)
        		image.setImageResource(R.drawable.five);
        	if(groupPosition == 5)
        		image.setImageResource(R.drawable.six);
        	if(groupPosition == 6)
        		image.setImageResource(R.drawable.seven);
        	if(groupPosition == 7)
        		image.setImageResource(R.drawable.eight);
        	if(groupPosition == 8)
        		image.setImageResource(R.drawable.nine);
        	if(groupPosition == 9)
        		image.setImageResource(R.drawable.ten);
        	if(groupPosition == 10)
        		image.setImageResource(R.drawable.eleven);
        }  
        return convertView;  
    }  
  
    public boolean hasStableIds() {  
        return true;  
    }  
    // 子选项是否可以选择    
    public boolean isChildSelectable(int arg0, int arg1) {  
        // TODO Auto-generated method stub  
        return true;  
    }  
}  